# --coding:utf-8--
import pandas as pd

from FileHandlers.JsonFile import JRead


class xlsx2json:
    @staticmethod
    def do(filename, target, saveName=None, sourcePath=None, _index_col=None):
        if sourcePath is None:
            sourcePath = "./json/Init/"
        if saveName is not None:
            target = f"./json/Save/{saveName}/{target}"
        file = f"{sourcePath}{filename}.xlsx"
        if _index_col is not None:
            print(_index_col)
            df: pd.DataFrame = pd.read_excel(file, index_col=_index_col)
        else:
            df: pd.DataFrame = pd.read_excel(file, index_col="ID")
        df.to_json(target, force_ascii=False)
        return JRead(path=target)
    
